/*		Filename: 	logger.cpp
 *		Author:		彭望
 *		Date:		2012-01-11
 *		Use:		具体实现日志对象
 */
#include "logger.h"
bool Logger::isInited = false;
log4cpp::Category& Logger::logger = log4cpp::Category::getRoot();

log4cpp::Category& Logger::getLogger()
{
	if( !Logger::isInited )
	{
			Logger::init();
			Logger::isInited = true;
	}
	return Logger::logger;
}

RetCode_t Logger::init()
{
	using namespace log4cpp;
	OstreamAppender* osAppender = new OstreamAppender("osAppender", &cout);
	FileAppender* fileAppender = new FileAppender("fileAppender", "run.log");

	PatternLayout *layout = new PatternLayout();
	PatternLayout *fileLayout = new PatternLayout();
	const char *format = "[%d] %p %c %x - %m%n";
	layout->setConversionPattern(format);
	fileLayout->setConversionPattern(format);


	osAppender->setLayout( layout );
	fileAppender->setLayout( fileLayout );
	Logger::logger.addAppender(osAppender);
	Logger::logger.addAppender(fileAppender);
	Logger::logger.setPriority(Priority::DEBUG);

	return RET_OK;
}
